package com.aSemy.qotwReader.core.types;

/**
 * The types of reader that Calibre can convert to.
 * 
 * @author Adam Semenenko
 */
public enum ReaderType implements ArgumentOfCommand
{
    // this lists ebook readers that Calibre can convert to.
    // http://calibre-ebook.com/user_manual/cli/ebook-convert-3.html#cmdoption-ebook-convert-shtml-epub--input-profile
    cybookg3,
    cybook_opus,
    defaultReader("default"), // because default is a keyword in Java
    hanlinv3,
    hanlinv5,
    illiad,
    irexdr1000,
    irexdr800,
    kindle,
    msreader,
    mobipocket,
    nook,
    sony,
    sony300,
    sony900,
    ;
    /** The name of the reader as a string. */
    final private String name;
    
    /** 
     * Used if the name of the reader is exactly the same as the enum variable.
     */
    private ReaderType()
    {
        this.name = super.toString(); // This returns the name of the enum variable.
    }
    /**
     * Use if the name of the reader is different from the enum variable.
     * For example, default can't be used as an enum because it's a keyword.
     * @param name The name of the ebook reader.
     */
    private ReaderType(String name)
    {
        this.name = name;
    }
    
    /**
     * Gets the name of the ebook reader.
     */
    @Override
    public String toString() { return this.name; }
    
    /**
     * Given a string this will attempt to find a matching ebook reader. If none exists it will return null.
     * @param string The string to match to an ebook reader.
     * @return An ebook reader with the same name as given in the string. Returns null if there is no match.
     */
    public static ReaderType getReaderFromString(String string)
    {
        for (ReaderType r : ReaderType.values())
            if (string.equalsIgnoreCase(r.name))
                return r;
        
        return null;
    }
}
